<template>
    <div>
        <el-form  :model="params" label-width="150px">
            <el-form-item label="激活码类型">
                <el-select v-model="params.type" placeholder="分类">
                    <el-option :label="item.value" :value="item.name" v-for="(item,index) in codeType" :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="生成数量">
                <el-input v-model="params.number" placeholder="批量生成邀请码数量"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="generate">批量生成</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import api from '@/api'
    import Exp from '@/utils/validateFrom'
    import {codeType} from '@/config'
    export default {
        data() {
            return {
                dialogVisible: false,
                sourceData: [],
                codeType:codeType,
                params: {
                    type: 'employer',
                    pageNumber: 1,
                    pageSize: 10,
                    number:''
                }
            }
        },
        created(){
        },
        methods: {
            generate(){
                let _this = this
                if(!this.params.number){
                    this.$message({
                        type: 'error',
                        message: '请填写正确的生成数量!'
                    });
                    return false;
                }
                api.postCodeGenerate(this.params).then((res) => {
                    if (res.code == 200) {
                        let {data} = res;
                        this.$confirm('批量生成成功，是否继续？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            location.reload()
                        }).catch(() => {
                            this.$router.push('/activecode/list')
                        });
                        // this.$message({
                        //         type: 'success',
                        //         message: '批量生成成功!',
                        //         duration:2000
                        //         });
                    }
                })
            },
        },
        components: {}
    }
</script>


<style lang="scss">
.el-input{
    width:auto;
}
</style>

